/*     */ package com.hs.activation.common.utils;
/*     */ 
/*     */ import java.nio.charset.StandardCharsets;
/*     */ import java.security.InvalidAlgorithmParameterException;
/*     */ import java.security.InvalidKeyException;
/*     */ import java.security.NoSuchAlgorithmException;
/*     */ import javax.crypto.BadPaddingException;
/*     */ import javax.crypto.Cipher;
/*     */ import javax.crypto.IllegalBlockSizeException;
/*     */ import javax.crypto.NoSuchPaddingException;
/*     */ import javax.crypto.spec.IvParameterSpec;
/*     */ import javax.crypto.spec.SecretKeySpec;
/*     */ 
/*     */ public final class Aes
/*     */ {
/*     */   private static final String KEY = "H%u$a*S&ha998I;n";
/*     */   private static final String IV = "X&(G*&^%#$^QHJC8";
/*     */   
/*     */   private Aes() {
/*  20 */     throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static String encrypt(String sSrc, String key) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
/*  32 */     byte[] raw = "H%u$a*S&ha998I;n".getBytes(StandardCharsets.UTF_8);
/*  33 */     SecretKeySpec sKeySpec = new SecretKeySpec(raw, "AES");
/*     */     
/*  35 */     Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
/*     */     
/*  37 */     IvParameterSpec iv = new IvParameterSpec("X&(G*&^%#$^QHJC8".getBytes(StandardCharsets.UTF_8));
/*  38 */     cipher.init(1, sKeySpec, iv);
/*  39 */     byte[] encrypted = cipher.doFinal(sSrc.getBytes(StandardCharsets.UTF_8));
/*     */     
/*  41 */     return parseByte2HexStr(encrypted).toUpperCase();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static String parseByte2HexStr(byte[] buf) {
/*  51 */     StringBuffer sb = new StringBuffer();
/*  52 */     for (int i = 0; i < buf.length; i++) {
/*  53 */       String hex = Integer.toHexString(buf[i] & 0xFF);
/*  54 */       if (hex.length() == 1) {
/*  55 */         hex = "0" + hex;
/*     */       }
/*  57 */       sb.append(hex.toUpperCase());
/*     */     } 
/*  59 */     return sb.toString();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static byte[] parseHexStr2Byte(String hexStr) {
/*     */     try {
/*  70 */       if (hexStr.length() < 1) {
/*  71 */         return null;
/*     */       }
/*  73 */       byte[] result = new byte[hexStr.length() / 2];
/*  74 */       for (int i = 0; i < hexStr.length() / 2; i++) {
/*  75 */         int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
/*  76 */         int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16);
/*  77 */         result[i] = (byte)(high * 16 + low);
/*     */       } 
/*  79 */       return result;
/*  80 */     } catch (Exception ex) {
/*  81 */       return null;
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static String decrypt(String sSrc, String key) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
/*  94 */     byte[] raw = "H%u$a*S&ha998I;n".getBytes(StandardCharsets.UTF_8);
/*  95 */     SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
/*  96 */     Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
/*  97 */     IvParameterSpec iv = new IvParameterSpec("X&(G*&^%#$^QHJC8".getBytes(StandardCharsets.UTF_8));
/*  98 */     cipher.init(2, skeySpec, iv);
/*     */ 
/*     */ 
/*     */     
/* 102 */     byte[] encrypted1 = parseHexStr2Byte(sSrc);
/* 103 */     if (encrypted1 != null) {
/* 104 */       byte[] original = cipher.doFinal(encrypted1);
/* 105 */       String originalString = new String(original, StandardCharsets.UTF_8);
/* 106 */       return originalString;
/*     */     } 
/* 108 */     return "";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static String encrypt(String source) throws Exception {
/* 118 */     return encrypt(source, "H%u$a*S&ha998I;n");
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static String decrypt(String source) throws Exception {
/* 128 */     return decrypt(source, "H%u$a*S&ha998I;n");
/*     */   }
/*     */ }


/* Location:              C:\Users\yzc\Desktop\新建文件夹 (3)\activation-0.0.16.jar!\BOOT-INF\classes\com\hs\activation\commo\\utils\Aes.class
 * Java compiler version: 16 (60.0)
 * JD-Core Version:       1.1.3
 */